package bitetorrent.model;

import java.util.ArrayList;

/**
 *
 * @author user
 */
public class FileDownloaderContainer extends ArrayList<FileDownloader> {

    public FileDownloader find(String infoHash) {
        FileDownloader file = null;

        for(int i=0; i < this.size(); ++i) {
            file = this.get(i);
            if (file.torrent.infoHash.equals(infoHash)) {
                break;
            }
        }

        return file;
    }

    public byte[] getBitField(String infoHash) {
        FileDownloader file = find(infoHash);

        if (file == null) {
            return null;
        }

        return file.getBitField();
    }

    public byte[] getPiece(String fileName, int index, int begin, int length) {
        FileDownloader file = find(fileName);

        return (file == null) ? null : file.getPiece(index, begin, length);
    }
}